# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Cilyan Olowen <gaknar@gmail.com>
# Contributor: fill <mailbox@fillo.ru>
# Contributor: Anton Shestakov <engored*ya.ru>

pkgname=flashrom
pkgver=1.2
pkgrel=4
pkgdesc="Utility for reading, writing, erasing and verifying flash ROM chips"
arch=(loong64 x86_64)
url="https://www.flashrom.org/"
license=(GPL)
depends=(libftdi pciutils libusb)
makedepends=(meson)
optdepends=('dmidecode: for SMBIOS/DMI table decoder support')
source=("https://download.flashrom.org/releases/${pkgname}-v${pkgver}.tar.bz2"{,.asc}
0001-Loongson-3-SPI-tmp.patch
0002-Speed-up.patch
0003-Add-support-for-loongarch64.patch
)

sha256sums=('e1f8d95881f5a4365dfe58776ce821dfcee0f138f75d0f44f8a3cd032d9ea42b'
            'SKIP')
validpgpkeys=(58A4868B25C7CFD662FB0132A3EB95B8D9780F68) # David Hendricks (packaging key) <david.hendricks@gmail.com>


prepare() {
    cd ${pkgname}-v${pkgver}
    patch -p1 -i "$srcdir/0001-Loongson-3-SPI-tmp.patch"
    patch -p1 -i "$srcdir/0002-Speed-up.patch"
    patch -p1 -i "$srcdir/0003-Add-support-for-loongarch64.patch"
}

build() {
  cd ${pkgname}-v${pkgver}
  arch-meson ../build \
      -Dconfig_loongson3_spi=true \
      -Dconfig_nic3com=false \
      -Dconfig_satamv=false \
      -Dconfig_satasii=false \
      -Dconfig_nicrealtek=false \
      -Dconfig_rayer_spi=false
  ninja -v -C ../build
  # Workaround for meson not installing manpage
  make
}

package() {
  DESTDIR="${pkgdir}" ninja -C build install
  # Workaround for meson not installing manpage
  cd ${pkgname}-v${pkgver}
  make PREFIX=temp/ install
  cp -r temp/share "${pkgdir}"/usr/
}
sha256sums=('e1f8d95881f5a4365dfe58776ce821dfcee0f138f75d0f44f8a3cd032d9ea42b'
            'SKIP'
            'daa1baf186747b34d6e36c3497295b9c29978632d8b958e3a2d08fd11fd035b5'
            'e8c2801791ca22f391a6820e83bd1bedf2be3aeb97057b12d3b718d467c4f115'
            '5e1700d8d90353b721f39f4dc030131277083e3e15b9d0265bbc6473604b228f')
